<?php echo $this->getHtml()->jsFile($this->base_url . '/static/common/js/jquery-1.4.4.js'); ?>
<?php echo $this->getHtml()->jsFile($this->base_url . '/static/common/js/ajaxfileupload.js'); ?>

<script type="text/javascript">
function ajaxFileUpload() {
	jQuery("#little_picture_loading").ajaxStart(function() {
		jQuery("#little_picture_img").hide();
		jQuery(this).show();
	}).ajaxComplete(function() {
		jQuery(this).hide();
		jQuery("#little_picture_img").show();
	});
	
	jQuery.ajaxFileUpload({
		url: "<?php echo $this->util->getUrlByCtrl('edit_submit', array('do' => 'upload')); ?>",
		secureuri: false,
		fileElementId: "little_picture_file",
		dataType: "json",
		success: function(ret, status) {
			if(ret.err_no != 0) {
				alert(ret.err_msg);
			}
			else {
				var savePath = ret.data.save_path;
				var saveUrl = "<?php echo $this->root_url; ?>" + savePath;
				jQuery("#little_picture_img").attr("src", saveUrl);
				jQuery(":hidden[name='little_picture']").val(savePath);
			}
		},
		error: function (ret, status, e) {
			alert(e);
		}
	});
	
	return false;
}

jQuery(document).ready(function($) {
	var littlePicture = $(":hidden[name='little_picture']").val();
	if (littlePicture != "") {
		$("#little_picture_img").attr("src", "<?php echo $this->root_url; ?>" + littlePicture);
		$("#little_picture_img").show();
	}
});
</script>

<?php
return array(
	'columns' => array(
		'post_title',
		'little_picture_file' => array(
			'label' => '缩略图',
			'name' => 'little_picture_file',
			'type' => 'file',
			'attributes' => array(
				'id' => 'little_picture_file',
				'onchange' => 'return ajaxFileUpload();',
			)
		),
		'little_picture_img' => array(
			'__multi__' => true,
			array(
				'type' => 'img',
				'name' => 'little_picture_loading',
				'value' => $this->imgs_url . '/ajaxLoading.gif',
				'attributes' => array(
					'id' => 'little_picture_loading',
					'style' => 'display: none',
				)
			),
			array(
				'type' => 'img',
				'name' => 'little_picture_img',
				'value' => '',
				'attributes' => array(
					'id' => 'little_picture_img',
					'style' => 'display: none',
					'width' => '200px',
					'height' => '200px',
				)
			),
		),
		'post_status',
		'post_flags',
		'post_url',
		'category_id',
		'post_content' => array(
			'type' => 'fckeditor',
			'attributes' => array(
				'toolbar' => 'Posts'
			)
		),
		'post_order' => array(
			'value' => 50,
		),
		'access_count' => array(
			'value' => mt_rand(0, 100),
		),
		'is_html',
		'allow_comment',
		'post_description',
		'post_keywords',
		'dt_created' => array(
			'value' => date('Y-m-d H:i:s')
		),
		'dt_modify' => array(
			'value' => '新发布'
		),
		'__buttons__' => array(
			'__multi__' => true,
			array(
				'type' => 'hidden',
				'name' => 'little_picture'
			),
			array(
				'type' => 'hidden',
				'name' => 'do',
				'value' => 'post',
			),
			array(
				'type' => 'submit',
				'value' => '提交',
				'attributes' => array(
					'class' => 'button blue'
				)
			),
			array(
				'type' => 'reset',
				'value' => '重置',
				'attributes' => array(
					'class' => 'button'
				)
			)
		)
	),
	'form' => $this->util->getForm('Posts', 'post'),
	'data' => $this->data,
	'errors' => $this->errors
);
?>